package org.aplikator.client.local.widgets;

import com.github.gwtbootstrap.client.ui.ControlGroup;
import com.github.gwtbootstrap.client.ui.ControlLabel;
import com.github.gwtbootstrap.client.ui.Controls;
import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
import com.google.gwt.user.client.ui.Composite;
import org.aplikator.client.shared.descriptor.PropertyDTO;

import java.io.Serializable;

public abstract class DataFieldBase extends Composite {

    protected PropertyDTO property;
    protected ControlLabel label;
    protected Controls controls;
    protected ControlGroup wrapper;

    protected boolean dirty;

    public DataFieldBase(String label, PropertyDTO property) {
        wrapper = new ControlGroup();
        if (label != null) {
            this.label = new ControlLabel(label);
        }
        this.controls = new Controls();
        initWidget(wrapper);
        if (label != null) {
            wrapper.add(this.label);
        }
        wrapper.add(this.controls);

        this.property = property;
    }

    public PropertyDTO getProperty() {
        return property;
    }

    public void setDirty(boolean dirty){
        this.dirty=dirty;
        if(dirty){
            wrapper.setType(ControlGroupType.SUCCESS);
        } else {
            wrapper.setType(ControlGroupType.NONE);
        }

    }

    public boolean isDirty(){
        return dirty;
    }

}
